package ua.maxicash.vo;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import javax.validation.constraints.Size;
import java.sql.Date;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "worker")
@PrimaryKeyJoinColumn (name="ID_USER")
@JsonIgnoreProperties({"scheduleList","works"})
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Worker extends SystemUser {

    @Column(name = "SEX")

    private int sex;

    @Past(message = "Date should be less then now")
    @NotNull(message = "Date of birth is required")
    @Column(name = "Date_of_Birth")
    private Date dateOfBirth;

    @ManyToMany
	@JoinTable(name = "Worker_JobType", joinColumns = {@JoinColumn(name = "ID_USER")}, 
			inverseJoinColumns = {@JoinColumn(name = "ID_JOB")})
	@LazyCollection(LazyCollectionOption.FALSE)
    @org.hibernate.annotations.Cascade(value={org.hibernate.annotations.CascadeType.SAVE_UPDATE})
	@Size(min = 1)
    private Set<JobType> jobTypes = new HashSet<JobType>();

    @OneToMany(fetch=FetchType.EAGER)
    @JoinColumn(name = "ID_USER")
    @org.hibernate.annotations.Cascade(value = { org.hibernate.annotations.CascadeType.SAVE_UPDATE })
    private Set<WorkersFreeTime> scheduleList = new HashSet<WorkersFreeTime>();

    @ManyToMany
	@JoinTable(name = "Work_Worker", joinColumns = {@JoinColumn(name = "ID_USER")},
			inverseJoinColumns = {@JoinColumn(name = "ID_WORK")})
	@LazyCollection(LazyCollectionOption.FALSE)
    @org.hibernate.annotations.Cascade(value={org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    private Set<Work> works = new HashSet<Work>();

    public Worker() {
    }
    
	public Set<JobType> getJobTypes() {
        return jobTypes;
    }

    public void setJobTypes(Set<JobType> jobTypes) {
        this.jobTypes = jobTypes;
    }

    public Date getDateOfBirth() {
        return dateOfBirth;
    }

    public void setDateOfBirth(Date dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    public Set<WorkersFreeTime> getScheduleList() {
        return scheduleList;
    }

    public void setScheduleList(Set<WorkersFreeTime> scheduleList) {
        this.scheduleList = scheduleList;
    }
    
    public Set<Work> getWorks() {
		return works;
	}

	public void setWorks(Set<Work> works) {
		this.works = works;
	}

}